package midend.IR_Instruction;

import midend.IR_Value.IR_BaseBlock;
import midend.IR_Value.IR_Value;

import java.util.ArrayList;
import java.util.List;

public class PCopy_Instruction extends Instruction{
    private ArrayList<IR_Value> before = new ArrayList<>();
    private ArrayList<IR_Value> now = new ArrayList<>();
    private IR_BaseBlock pastbb = null;

    public PCopy_Instruction(List<IR_Value> nop) {
        super(nop,null);
    }

    public ArrayList<IR_Value> getBefore() {
        return this.before;
    }

    public ArrayList<IR_Value> getNow() {
        return this.now;
    }

    public IR_BaseBlock pastbb() {
        return pastbb;
    }

    public void setPastbb(IR_BaseBlock pastbb) {
        this.pastbb = pastbb;
    }

    public void addCopy(List<IR_Value> values) {
        //phi  now(指代的是可以选择的，当前选择的)
        set_Op(0,values.get(0));
        set_Op(1,values.get(1));
        this.before.add(values.get(0));
        this.now.add(values.get(1));
    }

    public String toString(){
        //todo  确定一下下面copy语句的正确性
        if(get_op().isEmpty()){
            return null;
        }
        return get_op_index(0).get_ValueName() + " = copy " + get_op_index(1).get_ValueName();
    }
}
